package servicedevmap

import (
	"emsctrl/public"
)

const (
	PCS_DEV_TYPE   = "pcs"
	BMS_DEV_TYPE   = "bms"
	METER_DEV_TYPE = "meter"
)

func upGradeDevData(index int, devtype, devname, paratype string, datum public.DataVal) devmap {
	var devm devmap
	switch devtype {
	case PCS_DEV_TYPE:
		devm = &pcsdevMap{}
		//pcsdevMap.upGradeDevData(index, devtype, devname, paratype, datum)
		break
	case BMS_DEV_TYPE:
		//upGradeBmsDevData(index, devtype, devname, paratype, datum)
		devm = &bmsdevMap{}
		break
	case METER_DEV_TYPE:
		devm = &meterdevMap{}
	}
	devm.upGradeDevData(index, devtype, devname, paratype, datum)
	return devm
}

func GradeupCollodata(msg public.ReportDataMsg) {
	find := false
	var mapv devmap
	for i, m := range StationMap {
		switch i {
		case 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12:
			if _, ok := m[msg.DevType]; ok {
				if _, ok = m[msg.DevType][msg.DevName]; ok {
					for _, datum := range msg.Data {
						mapv = upGradeDevData(i, msg.DevType, msg.DevName, msg.ParaType, datum)
						find = true
					}
				}
			}
			break
		case 255:
			if _, ok := m[msg.DevType]; ok {
				if _, ok = m[msg.DevType][msg.DevName]; ok {
					for _, datum := range msg.Data {
						mapv = upGradeDevData(i, msg.DevType, msg.DevName, msg.ParaType, datum)
						find = true
					}
				}
			}
			break
		default:
			find = false
			break
		}
		if find == true {

			mapv.upGradeCurrPolicyPara(msg.DevType, msg.DevName, msg.ParaType)

			break
		}
	}

}
